package com.parsechina.hpush.broker.parser;

import io.netty.handler.codec.mqtt.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author linfeng
 * @since 2016/11/22
 */
public class SubAckMessage extends PushMessage {
    private static final long serialVersionUID = 5186333543708691142L;

    private MqttSubAckMessage subAckMessage;
    private List<Integer> qosTypeList = new ArrayList<>();
    private int messageId;

    public SubAckMessage(MqttSubAckMessage msg) {
        super(msg);
        this.subAckMessage = msg;
    }

    public SubAckMessage() {
    }

    public void addType(MqttQoS qoS) {
        qosTypeList.add(qoS.value());
    }

    public int getMessageId() {
        return messageId;
    }

    public void setMessageId(int messageId) {
        this.messageId = messageId;
    }

    public MqttSubAckMessage build() {
        MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId);
        MqttSubAckPayload payload = new MqttSubAckPayload(qosTypeList);
        return new MqttSubAckMessage(fixedHeader, variableHeader, payload);
    }


}
